package documenteditor;

import java_cup.runtime.Symbol;
import java.io.*;
%%
%{
	FileWriter     DC_fWriter;
	PrintWriter    DC_Salida;
	String			strCad;

  public void imprime_error(String str) throws IOException{
	try{
		strCad = "Error lexico con caracter '"+ str + "' en la columna "+(yychar+1)+" y fila "+(yyline+1) + " ha sido omitido";
		DC_fWriter = new FileWriter("c:\\ErroresPersonaje.txt",true);
		DC_Salida = new PrintWriter(DC_fWriter);
		DC_Salida.println(strCad);
		DC_fWriter.close();
    	System.out.println(strCad);
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
  }
%}
%init{
	try{
		FileWriter     DC_fWriter;
		PrintWriter    DC_Salida;
		String			strCad;
		DC_fWriter = new FileWriter("c:\\ErroresPersonaje.txt",false);
		DC_Salida = new PrintWriter(DC_fWriter);
		DC_Salida.println("/******* ERRORES ARCHIVO PERSONAJE *******/");
		DC_Salida.println("");
		DC_fWriter.close();
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
%init}
%public
%class lexUsr
%cup
%full
%line
%char
%ignorecase
%eofval{
	return (new Symbol(SimUsr.EOF));
%eofval} 
letra = [A-Za-z]
num = [0-9]
%%

"," {  return new Symbol(SimUsr.COMA, new token(yytext(), (yychar+1), (yyline+1))); }
";" {  return new Symbol(SimUsr.PCOMA, new token(yytext(), (yychar+1), (yyline+1))); }
([^"\""^" "^","^";"^"#"^"&"])+ {  return new Symbol(SimUsr.CADENA, new token(yytext(), (yychar+1), (yyline+1))); }


[\n] {yychar = 0;}
[ \t\r\f] { /* ignore white space. */ }
. { imprime_error(yytext()); ;}